import 'package:flutter/material.dart';
import 'views.dart';

class LoadingDialog extends Dialog {
  final String message;

  LoadingDialog({Key key, @required this.message}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Material(
      type: MaterialType.transparency,
      child: Center(
        child: SizedBox(
          width: 120,
          height: 120,
          child: Container(
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(8))),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                new CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation(main_theme_color),
                ),
                new Padding(
                  padding: const EdgeInsets.only(top: 20),
                  child: Text(message, style: TextStyle(fontSize: 12)),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class ConfirmDialog extends Dialog {
  final String message;

  ConfirmDialog({Key key, @required this.message}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Material(
      type: MaterialType.transparency,
      child: Center(
        child: Container(
          width: 120,
          height: 120,
          child: Container(
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(8))),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                new CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation(main_theme_color),
                ),
                new Padding(
                  padding: const EdgeInsets.only(top: 20),
                  child: Text(message, style: TextStyle(fontSize: 12)),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

void showLoadingDialog(BuildContext context, {String message = "请求中..."}) {
  showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return LoadingDialog(message: message);
      });
}

void showSnackBar(BuildContext context, String content) {
  Scaffold.of(context).showSnackBar(
      SnackBar(content: Text(content), duration: Duration(seconds: 3)));
}
